package com.qianli.cashmama.trade.openApi.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fqgj.common.utils.HttpUtil;
import com.jsoniter.output.JsonStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Amarendar
 * Date: 2020/6/2
 * Time: 下午3:42
 */
public class DingTalkPushUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(DingTalkPushUtils.class);

    //    private static final String DING_URL = "https://oapi.dingtalk.com/robot/send?access_token=b0a9315499e130fb0077e31b7207a4521b828bd7e4a7c528c7db2e4fd85f93d9";
    private static final String DING_URL = "https://oapi.dingtalk.com/robot/send?access_token=eebdd6e5418bc552c0d0d00dd38545d7982d022126fdf118aeacd3373b3b2562";


    public static void pushToAgent(String agentUrl, String ddUrl, String content) {

        Map<String, String> body = new HashMap<>();
        body.put("webhook", ddUrl);
        body.put("content", content);

        String response = HttpUtil.postPageBody(agentUrl, getPostHeaderMap(), JsonStream.serialize(body));

        LOGGER.info("== 钉钉推送agent结果 ==,response:{}", response);

    }

    private static Map getPostHeaderMap() {
        Map<String, String> postHeaderObject = new HashMap<>(1);
        postHeaderObject.put("Content-Type", "application/json");
        return postHeaderObject;
    }
}
